package com.zues.thread.design_mode.produce_consumer;

import lombok.extern.slf4j.Slf4j;

/**
 * 测试生产者---消费者模式
 */
@Slf4j(topic = "c.TestProduceConsumer")
public class TestProduceConsumer {

    public static void main(String[] args) {
        MessageQueue queue = new MessageQueue(2);
        for (int i = 0; i < 3; i++) {
            final int id = i;
            new Thread(() -> {
                queue.put(new Message(id, "值" + id));
            },"生产者" + i).start();
        }



        new Thread(() -> {
            while (true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                Message message = queue.take();
            }
        },"消费者").start();
    }

}
